<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['buytype']=array('0'=>'普通','1'=>'多商户','2'=>'货到付款','3'=>'自提','4'=>'加星','5'=>'砍价','6'=>'拼团','7'=>'秒杀','8'=>'抽奖','9'=>'夺宝');
$return['orderstatus']=array('1'=>'待发货','2'=>'待收货','3'=>'已完成','4'=>'已关闭','5'=>'申请维权','6'=>'已维权');
$return['paytype']=get_pay_types();
$return['ispay']=array('0'=>'未支付','1'=>'已支付');
$return['status']=array('0'=>'未核销','1'=>'已核销');
if($_RQ['op']=='list'){
	$return['params']=array();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'clerk_id'=>$_SESSION['uid']);
    $orderby='verifytime desc';
	$total='';
	if(!empty($_RQ['orders'])){
		$params['ordersn']=trim($_RQ['ordersn']);
		$return['params']['ordersn']=$_RQ['ordersn'];
	}

	if(!empty($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['verifytime']){
		$time_range=cfc('tools')->base64_decode($_RQ['verifytime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['verifytime']=$time_range;
		$params['verifytime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$return['list']=pdo_getslice('jy_weishop_order_self',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		$order=pdo_get('jy_weishop_order',array('id'=>$v['orderid']),array('price','mid','ordersn','buytype','paytype','status'));
		$v['orderstatus']=$order['status'];
		$v['orderstatustitle']=$this->order_status[$order['status']];
		$v['paytype']=$order['paytype'];
		$v['price']=$order['price'];
		$v['ordersn']=$order['ordersn'];
		$v['mid']=$order['mid'];
		$v['buytype']=$order['buytype'];
		$v['member']=model('core/member')->detail($order['mid'],array('nickname','mobile'));
		$v['verifytime']=date('Y-m-d H:i:s',$v['verifytime']);
		$v['saler']=pdo_getcolumn('jy_weishop_store_worker',array('mid'=>$v['clerk_id']),'name');
		$v['store']=pdo_getcolumn('jy_weishop_store',array('id'=>$v['storeid']),'title');
		$v['goods']=pdo_getall('jy_weishop_order_goods',array('orderid'=>$v['orderid'],'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
		foreach($v['goods'] as &$gv){
			$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice','unit','image','title','merchid'));
			$goodsinfo['total']=$gv['total'];
			$goodsinfo['price']=$gv['price'];
			if($_SESSION['is_tomedia']){
				$goodsinfo['image']=$goodsinfo['image']?tomedia($goodsinfo['image']):'';
			}
			$goodsinfo['weight']=pdo_getcolumn('jy_weishop_goods_dispatch',array('goodsid'=>$gv['goodsid']),'weight');
			//商品规格
			if($gv['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$gv['optionid']),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$goodsinfo['selespename']=implode("，",$specs);
			}
			//获取商户
			$gv = $goodsinfo;
		}
	}
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>array(
			array('op'=>'list','title'=>'核销记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'nickname','title'=>'买家','type'=>'string'),
			array('name'=>'price','title'=>'金额','type'=>'string'),
			array('name'=>'orderstatus','title'=>'订单状态','type'=>'radio','options'=>'orderstatus'),
			array('name'=>'buytype','title'=>'订单类型','type'=>'radio','options'=>'buytype'),			
			array('name'=>'verifytime','title'=>'核销时间','type'=>'string'),
			array('name'=>'store','title'=>'核销门店','type'=>'string'),	
			array('name'=>'saler','title'=>'核销员','type'=>'string'),
			array('name'=>'paytype','title'=>'支付方式','type'=>'radio','options'=>'paytype'),			
		),
		'action'=>array(	
			array('type'=>'href','op'=>'orderdetail','title'=>'订单详情'),
		),),
		
		'search'=>array(
			array('name'=>'ordersn','width'=>15,'title'=>'订单号','type'=>'string'),
			array('type'=>'select','width'=>'15','title'=>'选择门店','name'=>'storeid','options'=>'stores','select_title'=>'请选择门店'),
			array('type'=>'time_range','width'=>'16','title'=>'核销时间','name'=>'verifytime','help'=>''),
		)
	);
	//$return['htmls']=$htmls;
	exi($return);
}
?>